//
//  DSBaseViewModel.m
//  DSJY
//
//  Created by 冯华强 on 16/10/16.
//  Copyright © 2016年 dsjy. All rights reserved.
//  父类VM

#import "DSBaseViewModel.h"

@implementation DSBaseViewModel

#pragma mark - 系统回调
- (instancetype)init
{
    if (self = [super init]) {
        self.pageNum = 1;
        self.pageCount = 15;
        self.timeDelay = 1.0;
        [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
        [SVProgressHUD setMinimumDismissTimeInterval:1.0];
    }
    return self;
}

#pragma mark - 外部方法
- (void)createCmdSignal:(RACDisposable * (^)(id<RACSubscriber> subscriber))didSubscribe
{
    _requestCommand = [[RACCommand alloc] initWithSignalBlock:^RACSignal *(id input) {
        self.pageNum = [input isEqual:@(YQRefreshTypeFooter)] ? self.pageNum+1 : 1;
        return [RACSignal createSignal:didSubscribe];
        
    }];
}

- (void)veriResponse:(YQResponse *)respone finishedCallBack:(void (^)())finishedCallBack
{
    if (respone.error_code == YQResponseCodeSuccess){
        finishedCallBack();
        return;
    }
    
    if (respone.error_code == YQResponseCodeTokenInvalid) {//session失效的发送通知
        [MTNotificationCenter postNotificationName:YQResponseCodeTokenInvalidNote object:respone.msg];
    }
}

/**
 *  设置请求时的提示框
 */
- (void)executingWithCommand:(RACCommand *)command
{
    //skip:1 跳过第一个（未进行）
    [[command.executing skip:1] subscribeNext:^(id x) {
        if ([x boolValue] == YES) {
            [SVProgressHUD show];
            MTLog(@"正在进行");
        }else{
            MTLog(@"已经完成");
        }
    }];
}

@end
